﻿Imports System.Data.SqlClient
Public Class Admin_Page
    Inherits System.Web.UI.Page
    Public btn As String
    Public dr As Data.DataRow
    Public i As Integer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'If IsPostBack Then
        If Session("userName") = "" Then
            Response.Redirect("default.aspx", True)
        End If

        Dim strID As String = btnHidden.Value

        Dim strCaption_Text As String = caption_text.Value

        If strCaption_Text = "Edit" Then
            Session("Edit_User") = strID
            Response.Redirect("Add_New_User.aspx")
        Else
            If strCaption_Text = "New" Then
                Session("Edit_User") = ""
                Response.Redirect("Add_New_User.aspx")
            End If
            If strID <> "" Then
                Disable(strID, strCaption_Text)
            End If

        End If
        ' End If



    End Sub

    Public Function dt_User() As System.Data.DataTable
        Dim dt As System.Data.DataTable
        Dim strSQL, strTable As String
        strTable = "[User]"
        strSQL = "SELECT * FROM [User]"
        Dim dts As New DataSet
        dts = CommonUtil.executeSQL(strSQL, strTable)
        dt = dts.Tables(strTable)
        Return dt
    End Function
  
    Public Sub Disable(ByVal user_ID As String, ByVal caption_text As String)

        Dim strSQL, strMsg As String
        strMsg = ""
        If user_ID = "v000" Then
            strMsg = "You cannot modify POWER USER!"
        Else

            If caption_text = "True" Then
                strSQL = "UPDATE [User] SET User_Expired='FALSE' FROM [User] WHERE User_Number='" & user_ID & "'"
            Else
                strSQL = "UPDATE [User] SET User_Expired='TRUE' FROM [User] WHERE User_Number='" & user_ID & "'"
            End If

            If CommonUtil.commonExecuteNonQuery(strSQL) = True Then
                strMsg = ("Update successfully")
            Else
                strMsg = ("Fail to Update")
            End If
        End If
        lblMsg.Text = strMsg


    End Sub

    Public Sub Edit_User(ByVal user_ID As String)
        Session("Edit_User") = user_ID
        Response.Redirect(".aspx")
    End Sub


End Class